/*
 * DevApplication.h
 *
 *  Created on: 2019-07-01
 *      Author: chuanjiang.zh
 */

#ifndef DevApplication_H_
#define DevApplication_H_

#include "CApplication.h"
#include "CHttpService.h"

#include "TMap.h"

#include "StringMap.h"
#include <atomic>

#include "MinuteTimer.h"


class DevApplication : public CApplication
	
{
public:

    typedef std::function< void(bool) > BoolResultHandler;


public:
	DevApplication();
	virtual ~DevApplication();

	virtual std::string getConfigPath();
	virtual std::string getLogFilePath();

	HttpRestServer& getHttpService();

	void delayExit();

	std::string	getLocalHost();

	void test();

	std::string getStoragePath();
	
	std::string	getImageDirPath();


public:

	void webcast(const char* method, const Json::Value& body);



public:

	void reloadDbConfig();

protected:
	virtual bool init();
	virtual void uninit();

	void construct();

protected:

protected:

protected:
	void onDeviceReady();

protected:

	void handleDeviceReady();

	template < class T>
	void notice(const char* method, const T& t);


protected:

protected:
	bool setupDb();

	bool setupHttp();
	void teardownHttp();

	void loadConfig();

	bool setupDevice();
	void teardownDevice();

	void handleNewDay(int64_t time, int mday);
	void handleNewHour(int64_t time, int mday, int hour);
	void handleNewMinute(int64_t time, int mday, int hour, int minute);

	void initDb();

	int64_t getTimestamp();

    void startDevice();
    void stopDevice();


protected:


protected:
	std::mutex  m_mutex;

	CHttpService	m_httpService;

	MinuteTimer		m_minuteTimer;
	//std::shared_ptr< DailyPlanScheduler>	m_planScheduler;

	std::shared_ptr< db::DbConnectionPool >	m_dbPool;



};


#endif /* DevApplication_H_ */
